;
(function () {
    new Vue({
        el: '#matter_detali',
        data: {
            quanxian: JSON.parse(window.localStorage.getItem('permissions')),
            block_elements: '',

            data:[],
        },
        methods: {
            //获取素材类型
            getmodules() {
                hlhttp.get({
                    url: 'configure/dict',
                    data: {
                        module_code: 'MNHU',
                        config_name: 'MNHU_PAGE_MATERIAL_TYPE',
                        parent_dict_code: '#',
                        key: '#',
                    },
                    success: (data) => {
                        this.modulesList = data;
                    }
                })
            },
            // 获取推荐服务列表
            getElements() {
                hlhttp.get({
                    url: 'jwk/recommend_services',
                    success: (data) => {
                        data.forEach(item =>{
                            item.isEdit = false
                            item.isLEdit = false
                            item.link = item.link?item.link:''
                            item.Editlink = JSON.parse(JSON.stringify(item.link))
                        })
                        this.data = data

                    }
                })
            },
            // 编辑可见或不可见
            editShow(item){
                if(item.showPageView == 'R'){
                    item.showPageView = 'V'
                }else{
                    item.showPageView = 'R'
                }
                this.editService(item)
            },
            //编辑虚拟浏览量
            editVir(item){
                item.isLEdit = !item.isLEdit
                this.editService(item)
            },
            editService(item){
                var that = this
                hlhttp.put({
                    url: 'jwk/recommend_service',
                    data: {
                        recommend_service_id: item.id,
                        show_page_view:item.showPageView,
                        virtual_page_views:item.virtualPageViews,
                        link:item.Editlink,
                    },
                    success: function () {
                        that.getElements();
                    }
                })
            },
            //编辑链接
            editUrl(item){
                item.isEdit = true
                item.Editlink = JSON.parse(JSON.stringify(item.link))
            },
            // 排序
            rank(item, type) {
                var that = this
                hlhttp.put({
                    url: 'jwk/recommend_service/_order',
                    data: {
                        recommend_service_id: item.id,
                        order:type,
                    },
                    success: function () {
                        that.getElements();
                    }
                })
            },
            //删除
            delItem(item){
                var that = this
                hllayer.confirm('确认要删除该服务吗?', () => {
                    hlhttp.delete({
                        url: 'jwk/recommend_service?recommend_service_id='+item.id,
                        data: {
                            recommend_service_id: item.id,
                        },
                        success: function () {
                            that.getElements();
                        }
                    })
                })

            },
            // 上传文件
            uploadFile(type) {
                this.showMatter = type
                $('.upload-file-button').trigger('click')
            },

            //编辑图片保存
            element_img(res) {
                var that = this
                hlhttp.post({
                    url: 'jwk/recommend_service',
                    data: {
                        img_url: res.json.url
                    },
                    success: function () {
                        that.getElements();
                    }
                })
            },


        },
        created() {
            hlSelectUi()
        },
        mounted() {
            this.getElements();
            var that = this
            imgupload('.upload-file-button', uploadUrl, function (res) {
                that.element_img(res)
            })
        }
    })
    function compareAsc(propertyName) {
        return function (object1, object2) {
          var value1 = object1[propertyName];
          var value2 = object2[propertyName];
          if (value2 < value1) {
            return 1;
          } else if (value2 > value1) {
            return -1;
          } else {
            return 0;
          }
        }
      }
}())
